package pub.pjoc.util;

import org.springframework.util.Assert;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author xiongyingqi
 * @since 16-11-22 下午5:51
 */
public abstract class DateUtils {
  public static final String DATE_FORMAT_LONG = "yyyy-MM-dd HH:mm:ss";
  public static final String DATE_FORMAT_SHORT = "yyyy-MM-dd";

  public static String getNowDate() {
    SimpleDateFormat simpleDateFormat = getDateFormat(DATE_FORMAT_SHORT);
    return simpleDateFormat.format(new Date());
  }

  public static String getNowDateTime() {
    SimpleDateFormat simpleDateFormat = getDateFormat(DATE_FORMAT_LONG);
    return simpleDateFormat.format(new Date());
  }

  public static SimpleDateFormat getDateFormat(String format) {
    Assert.hasText(format);
    return new SimpleDateFormat(format);
  }

  public static long getUnixTime() {
    return System.currentTimeMillis() / 1000;
  }
}
